package com.smartstate.IOC.controller;

import com.smartstate.IOC.service.HalfHourPowerMeterSummaryService;
import com.smartstate.IOC.util.StringDateUtills;
import com.smartstate.IOC.vo.PowerMeterSummaryRec;
import com.smartstate.common.web.httpResult.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/eneger")
@Api(tags = "能源汇总")
public class EnergymentControllr {

    @Autowired
    private HalfHourPowerMeterSummaryService powerMeterSummaryService;

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    @ApiOperation("综合态势-七日能耗，获取距今日最近七天的总能耗(包含今天为最后一天)")
    public List<PowerMeterSummaryRec> getAllEneger(){
        return powerMeterSummaryService.getPowerMeterSummaryRecs(StringDateUtills.getDayStyleStrFromDateTime(new Date(new Date().getTime()- 7*24*60*60*1000L)));
    }


    @RequestMapping(value = "/getPeriodDeviceSummaryRecs", method = RequestMethod.GET)
    @ApiOperation("能源态势-园区用电占比，获取园区设备用电占比")
    public ResultVO<Map<String,Map<String, BigDecimal>>> getPeriodDeviceSummaryRecs(){
        return ResultVO.success(powerMeterSummaryService.getPeriodDeviceSummaryRecs());
    }

    @RequestMapping(value = "/getTotalPower", method = RequestMethod.GET)
    @ApiOperation(value = "能源态势-区域用电统计，每栋近三天总电量")
    public Map<String,Map<String,BigDecimal>> getTotalPower(){
        return powerMeterSummaryService.getTotalPower();
    }

    @RequestMapping(value = "/getUnitPowers", method = RequestMethod.GET)
    @ApiOperation(value = "能源态势-园区单位用电统计，获取每层的用电量")
    public List<Map<String,Object>> getUnitPowers(){
        return powerMeterSummaryService.getUnitPowers();
    }

    @RequestMapping(value = "/getRatioOnMonth", method = RequestMethod.GET)
    @ApiOperation(value = "能源态势-用电环比，获取电量月环比")
    public ResultVO<List> getRatioOnMonth() {
        return ResultVO.success(powerMeterSummaryService.getRatioOnMonth()) ;
    }




    /**
     * 查询各个月份的用电总量
     */
    @GetMapping("/electricTotal")
    @ApiOperation(value = "查询各个月份的用电总量")
    public List<Map<String, Float>> getElectricDataTotal() {
        List<Map<String, Float>> electricDataTotal = powerMeterSummaryService.getElectricDataTotal();
        return electricDataTotal;
    }

}
